package com.huaxin.hxmodulestatisticalanalysis;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Order(0)
public class DeleteOperationAspect {
    @Around("execution(* removeById(..)) && " +
            "target(com.baomidou.mybatisplus.extension.service.IService)")
    public Object handleDeleteOperation(ProceedingJoinPoint joinPoint) throws Throwable {
        DeleteOperationContext.markAsDelete();
        try {
            Object result = joinPoint.proceed();
            System.out.println("✅ 方法执行成功，返回: " + result);
            return result;
        } finally {
            DeleteOperationContext.clear();
            System.out.println("🧹 ThreadLocal 已清除");
        }
    }
}